package router

import (
	"backend/config"
	"backend/internal/controller"
	"backend/middleware"

	"github.com/gin-gonic/gin"
	"github.com/google/wire"
)

var ProviderSet = wire.NewSet(NewRouter)

func NewRouter(
	conf *config.Configuration,
	jwtAuthM *middleware.JWTAuth,
	recoveryM *middleware.Recovery,
	limiterM *middleware.Limiter,
	userController *controller.UserController,
	uploadController *controller.UploadController,
) *gin.Engine {
	if conf.App.Env == "production" {
		gin.SetMode(gin.ReleaseMode)
	}
	router := gin.New()
	router.Use(gin.Logger(), recoveryM.Handler())

	// 限流处理
	router.Use(limiterM.Handler())
	// 静态资源目录
	router.Static("/doc", "./storage/doc")
	router.Static("/image", "./storage/image")
	router.Static("/video", "./storage/video")
	// 注册 admin
	SetAdminGroupRoutes(router, jwtAuthM, userController, uploadController)

	return router
}
